﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Yelper.Web.Controllers
{
    public class SearchController : Controller
    {
        //
        // GET: /Search/

        public ActionResult Index(string lambda)
        {
            using (yelperEntities entities = new yelperEntities()) {

                var tag = entities.LambdaTags.Include("Yelps.User").Where(l => l.Tag == lambda).SingleOrDefault();

                var yelps = new List<Yelp>();

                if (tag != null) {
                    yelps = tag.Yelps.OrderByDescending(x => x.YelpDate).Take(20).ToList();
                }

                ViewBag.SearchTag = lambda;
                ViewData.Model = yelps;

            }


            return View();
        }

    }
}
